from webs.service import config_service


# 页面标题行
def head(params):
    web = b''
    web += b'<!DOCTYPE html>'
    web += b'<html lang="en">'
    web += b'    <head>'
    web += b'      <meta charset="utf-8">'
    web += b'      <meta name="viewport" content="width=device-width, initial-scale=1">'
    web += b'      <meta name="keywords" content="">'
    web += b'      <meta name="description" content="">'
    web += b'      <meta name="author" content="">'
    web += b'      <link rel="icon" href="assets/images/favicon.png" type="image/png">'
    web += b'      <title>Home</title>'
    web += b'        <!--Begin  Page Level  CSS -->'
    web += b'        <link href="assets/plugins/morris-chart/morris.css" rel="stylesheet">'
    web += b'        <link href="assets/plugins/jquery-ui/jquery-ui.min.css" rel="stylesheet"/>'
    web += b'         <!--End  Page Level  CSS -->'
    web += b'        <link href="assets/css/icons.css" rel="stylesheet">'
    web += b'        <link href="assets/css/bootstrap.min.css" rel="stylesheet">'
    web += b'        <link href="assets/css/style.css" rel="stylesheet">'
    web += b'        <link href="assets/css/responsive.css" rel="stylesheet">'
    web += b'    </head>'
    web += b'<body class="sticky-header">'
    params['web'] = web
    return params


def tail(params):
    web = params['web']
    web += bytes('<script src="assets/js/jquery.min.js"></script>', encoding='utf-8')
    web += bytes('<script src="assets/js/bootstrap.min.js"></script>', encoding='utf-8')
    web += bytes('<script src="assets/plugins/moment/moment.js"></script>', encoding='utf-8')
    web += bytes('<script src="assets/js/jquery.slimscroll.js "></script>', encoding='utf-8')
    web += bytes('<script src="assets/js/jquery.nicescroll.js"></script>', encoding='utf-8')
    web += bytes('<script src="assets/js/functions.js"></script>', encoding='utf-8')
    web += bytes('<script src="assets/plugins/morris-chart/morris.js"></script>', encoding='utf-8')
    web += bytes('<script src="assets/plugins/morris-chart/raphael-min.js"></script>', encoding='utf-8')
    web += bytes('<script src="assets/pages/dashboard.js"></script>', encoding='utf-8')
    web += bytes('</body>', encoding='utf-8')
    web += b'</html>'
    params['web'] = web
    return params


# 菜单列表
def menu(params):
    url = params['url']
    web = params['web']
    web += bytes('<div class="left-side sticky-left-side">', encoding='utf-8')
    web += bytes('    <div class="logo">', encoding='utf-8')
    web += bytes('        <a href="index.html"><img src="assets/images/logo.png" alt=""></a>', encoding='utf-8')
    web += bytes('    </div>', encoding='utf-8')
    web += bytes('    <div class="logo-icon text-center">', encoding='utf-8')
    web += bytes('        <a href="index.html"><img src="assets/images/logo-icon.png" alt=""></a>', encoding='utf-8')
    web += bytes('    </div>', encoding='utf-8')
    web += bytes('    <!--logo-->', encoding='utf-8')
    web += bytes('    <div class="left-side-inner">', encoding='utf-8')
    web += bytes('        <ul class="nav nav-pills nav-stacked custom-nav">', encoding='utf-8')
    # 具体按钮
    if url == config_service.url0 or url == config_service.url1 or url == config_service.url14:
        web += b'<li class="menu-list nav-active">'
    else:
        web += b'<li class="menu-list">'
    web += bytes('<a href="index.html"><i class="icon-home"></i> <span>触发情况</span></a>', encoding='utf-8')
    web += bytes('   <ul class="sub-menu-list">', encoding='utf-8')
    web += bytes('      <li><a href="' + config_service.url14 + '">股票详情</a></li>', encoding='utf-8')
    web += bytes('      <li class="active"><a href="' + config_service.url0 + '">当日触发</a></li>', encoding='utf-8')
    web += bytes('      <li><a href="' + config_service.url1 + '">总体触发</a></li>', encoding='utf-8')
    web += bytes('   </ul>', encoding='utf-8')
    web += bytes('</li>', encoding='utf-8')

    if url == config_service.url5 or url == config_service.url6:
        web += b'<li class="menu-list nav-active">'
    else:
        web += b'<li class="menu-list">'
    web += bytes('<a href="#"><i class="icon-note"></i> <span>用户配置</span></a>', encoding='utf-8')
    web += bytes('   <ul class="sub-menu-list">', encoding='utf-8')
    web += bytes('      <li><a href="' + config_service.url5 + '">监控股票配置</a></li>', encoding='utf-8')
    web += bytes('      <li><a href="' + config_service.url6 + '">定时任务配置</a></li>', encoding='utf-8')
    web += bytes('   </ul>', encoding='utf-8')
    web += bytes('</li>', encoding='utf-8')

    if url == config_service.url4 or url == config_service.url10 or url == config_service.url11:
        web += b'<li class="menu-list nav-active">'
    else:
        web += b'<li class="menu-list">'
    web += bytes('<a href="#"><i class="icon-layers"></i> <span>后台管理</span></a>', encoding='utf-8')
    web += bytes('  <ul class="sub-menu-list">', encoding='utf-8')
    web += bytes('     <li><a href="' + config_service.url11 + '">股票代码</a></li>', encoding='utf-8')
    web += bytes('     <li><a href="' + config_service.url4 + '">监控代码</a></li>', encoding='utf-8')
    web += bytes('     <li><a href="' + config_service.url10 + '">修改配置</a></li>', encoding='utf-8')
    web += bytes('  </ul>', encoding='utf-8')
    web += bytes('</li>', encoding='utf-8')

    if url == config_service.url7 or url == config_service.url8:
        web += b'<li class="menu-list nav-active">'
    else:
        web += b'<li class="menu-list">'
    web += bytes('<a href="#"><i class="icon-pie-chart"></i> <span>数据验证</span></a>', encoding='utf-8')
    web += bytes('  <ul class="sub-menu-list">', encoding='utf-8')
    web += bytes('     <li><a href="' + config_service.url7 + '">均线+macd验证</a></li>', encoding='utf-8')
    web += bytes('     <li><a href="' + config_service.url8 + '">均线验证</a></li>', encoding='utf-8')
    web += bytes('  </ul>', encoding='utf-8')
    web += bytes('</li>', encoding='utf-8')

    web += bytes('<li class="menu-list">', encoding='utf-8')
    web += bytes('<a href="#"><i class="icon-lock"></i> <span>' + '登录' + '</span></a>', encoding='utf-8')
    web += bytes('  <ul class="sub-menu-list">', encoding='utf-8')
    web += bytes('     <li><a href="' + config_service.url2 + '"> 登录 </a></li>', encoding='utf-8')
    web += bytes('     <li><a href="' + config_service.url9 + '"> 注册 </a></li>', encoding='utf-8')
    web += bytes('  </ul>', encoding='utf-8')
    web += bytes('</li>', encoding='utf-8')

    web += bytes('        </ul>', encoding='utf-8')
    web += bytes('        <!--End sidebar nav-->', encoding='utf-8')
    web += bytes('    </div>', encoding='utf-8')
    web += bytes('</div>', encoding='utf-8')
    params['web'] = web
    return params


# 主显示模块
def wrapper(params):
    url = params['url']
    if 'respond_msg' in params.keys():
        msg = params['respond_msg']
    else:
        msg = {'code': 200, 'msg': " it's ok "}
    url_des = config_service.get_url_des(url)
    a = params['web']
    a += b'<div class="wrapper">'
    a += b'    <div class="page-title-box">'
    a += bytes('<h4 class="page-title">' + url_des + '</h4>', encoding='utf-8')
    a += b'        <ol class="breadcrumb">'
    a += b'            <li>'
    a += bytes('          <a href="#">' + msg['msg'] + '</a>', encoding='utf-8')
    a += b'            </li>'
    a += b'        </ol>'
    a += b'        <div class="clearfix"></div>'
    a += b'    </div>'
    a += params['text']
    a += b'</div>'
    params['web'] = a
    return params


# 标题行
def header_section(params):
    username = '约翰'
    if config_service.username in params.keys():
        username = params[config_service.username]
    a = params['web']
    a += b'    <!-- header section start-->'
    a += b'<div class="header-section">'
    a += b'    <a class="toggle-btn"><i class="fa fa-bars"></i></a>'
    a += b'    <form class="searchform">'
    a += b'        <input type="text" class="form-control" name="keyword" placeholder="Search here..."/>'
    a += b'    </form>'
    a += b'    <div class="menu-right">'
    a += b'        <ul class="notification-menu">'
    a += b'            <li>'
    a += b'                <a href="#" class="btn btn-default dropdown-toggle info-number" data-toggle="dropdown">'
    a += b'                    <i class="fa fa-tasks"></i>'
    a += b'                    <!--  <span class="badge">8</span> --> '
    a += b'                </a>'
    a += b'                <div class="dropdown-menu dropdown-menu-head pull-right">'
    a += b'                    <h5 class="title">You have 8 pending task</h5>'
    a += b'                </div>'
    a += b'            </li>'
    a += b'            <li>'
    a += b'                <a href="#" class="btn btn-default dropdown-toggle info-number" data-toggle="dropdown">'
    a += b'                    <i class="fa fa-bell-o"></i>'
    a += b'                </a>'
    a += b'                <div class="dropdown-menu dropdown-menu-head pull-right">'
    a += b'                    <h5 class="title">Notifications</h5>'
    a += b'                    <ul class="dropdown-list normal-list">'
    a += b'                        <li class="message-list message-scroll-list">'
    a += b'                            <a href="#">'
    a += b'                                <span class="photo"> <img src="assets/images/users/avatar-8.jpg" class="img-circle"'
    a += b'                                                          alt="img"></span>'
    a += b'                                <span class="subject">John Doe</span>'
    a += b'                                <span class="message"> New tasks needs to be done</span>'
    a += b'                                <span class="time">15 minutes ago</span>'
    a += b'                            </a>'
    a += b'                        </li>'
    a += b'                        <li class="last"><a href="#">All Messages</a></li>'
    a += b'                    </ul>'
    a += b'                </div>'
    a += b'            </li>'
    a += b'            <li>'
    a += b'                <a href="#" class="btn btn-default dropdown-toggle" data-toggle="dropdown">'
    a += b'                    <img src="assets/images/users/avatar-6.jpg" alt=""/>'
    a += bytes(username, encoding='utf-8')
    a += b'                    <span class="caret"></span>'
    a += b'                </a>'
    a += b'                <ul class="dropdown-menu dropdown-menu-usermenu pull-right">'
    a += b'                    <li><a href="#"> <i class="fa fa-wrench"></i> Settings </a></li>'
    a += b'                    <li><a href="#"> <i class="fa fa-user"></i> Profile </a></li>'
    a += b'                    <li><a href="#"> <i class="fa fa-info"></i> Help </a></li>'
    a += b'                    <li><a href="#"> <i class="fa fa-lock"></i> Logout </a></li>'
    a += b'                </ul>'
    a += b'            </li>'
    a += b'        </ul>'
    a += b'    </div>'
    a += b'</div>'
    params['web'] = a
    return params
